import numpy as np
import matplotlib.pyplot as plt

raw_data_X = [[3.393533211, 2.331273381, 4],
              [3.110073483, 1.781539638, 4],
              [1.343808831, 3.368360954, 3],
              [3.582294042, 4.679179110, 6],
              [2.280362439, 2.866990263, 7],
              [7.423436942, 4.696522875, 8],
              [5.745051997, 3.533989803, 6],
              [9.172168622, 2.511101045, 9],
              [7.792783481, 3.424088941, 10],
              [7.939820817, 0.791637231, 11],
              [7.792783481, 2.424088941, 12],
              [7.939820817, 1.791637231, 14],
              [7.792783481, 2.8024088941, 15],
              [7.939820817, 4.791637231, 16]
              ]
raw_data_y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0]

X = np.array(raw_data_X)
y = np.array(raw_data_y)



from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=66)

from sklearn.linear_model import LinearRegression
line_reg=LinearRegression()
line_reg.fit(X_train,y_train)
score=line_reg.score(X_test,y_test)
print(score)

#预测
y_predict=line_reg.predict(X_test)
print(y_predict)

print(f'系数：{line_reg.coef_}，b的值：{line_reg.intercept_}')

#性能指标
from sklearn.metrics import mean_absolute_error,mean_squared_error
mse=mean_squared_error(y_test, y_predict)
print(mse)

mae=mean_absolute_error(y_test, y_predict)
print(mae)
from sklearn.metrics import r2_score
r2=r2_score(y_test, y_predict)
print(r2)